import { Encrypter } from "../Encrypters/Encrypter";
import { ClientName } from "../Enums/ClientName";

export class EncrypterManager
{
    private static encrypters:{[key:string]:Encrypter} = {};
    public static GetEncrypter(clientName:string):Encrypter
    {
        if(this.encrypters[clientName]!=undefined)return this.encrypters[clientName];
        var encrypter:Encrypter = new Encrypter();
        this.encrypters[clientName] = encrypter;
        if(clientName==ClientName.LOBBY_CLIENT)
        {
            //encrypter.IsTrace = true;
            //encrypter.PacketIDs = [0x06];
            ///  需要压缩数据的规则
            // encrypter.Ruler.SetNeedCompressPacket(PacketID.LOGIN_IN,PacketMode.Send);
            // ///  需要解压缩数据的规则
            // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_LOGIN_IN,PacketMode.Receive);
            // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_UPDATE_MARQUEE, PacketMode.Receive);
            // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_REAL_TIME_BET_INFO, PacketMode.Receive);
            // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_Lobby_Theme_Subscribe, PacketMode.Receive);// 与游戏 消息S_FAIL_GAME ID号重复
            // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_LOBBY_INFO, PacketMode.Receive);
            // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_Maintenance, PacketMode.Receive);
            // ///  需要使用动态CDataKey的规则
            // encrypter.Ruler.SetNeedGenDynamicKey(PacketID.LOGIN_IN, PacketMode.Send);
            // encrypter.Ruler.SetNeedGenDynamicKey(PacketID.S_LOGIN_IN, PacketMode.Receive);
            // ////////////////////////////////////////////////////// BroadcastKey
            // // Client
            // encrypter.SetBroadcastKeyPacketID(PacketID.ACK, PacketMode.Send);
            // encrypter.SetBroadcastKeyPacketID(PacketID.N_ACK, PacketMode.Send);
            // encrypter.SetBroadcastKeyPacketID(PacketID.C_Heart, PacketMode.Send);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_Heart, PacketMode.Send);
            // // Server
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_ANNOUNCELIST, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_UPDATE_TABLE_INFO, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_UPDATE_DEALER_INFO, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_UPDATE_MARQUEE, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_CLEAR_MARQUEE, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_REAL_TIME_BET_INFO, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_GOOD_ROAD, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_UPDATE_LOBBY_INFO, PacketMode.Receive);
            
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_Lobby_Update_Table_Road, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_Maintenance, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.ACK, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.N_ACK, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.C_Heart, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.S_Heart, PacketMode.Receive);
            // encrypter.SetBroadcastKeyPacketID(PacketID.PEEK_PROGRESS, PacketMode.Send);
            // encrypter.SetBroadcastKeyPacketID(PacketID.PEEK_PROGRESS, PacketMode.Receive);
            // ////////////////////////////////////////////////////// PrivateKey
            // // Client
            // encrypter.SetPrivateKeyPacketID(PacketID.C_LOGIN_OUT, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_Lobby_Theme_Subscribe, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_BOSS_DEPUTY_REQUEST, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_BOSS_CANCEL_DEPUTY, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_SET_CHIP, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_LOGIN_LOBBY_OK, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_MultiTable_Entry, PacketMode.Send);
            // encrypter.SetPrivateKeyPacketID(PacketID.C_LOBBY_INFO, PacketMode.Send);
            // // Server
            // encrypter.SetPrivateKeyPacketID(PacketID.S_LOGIN_OUT, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_CHANGE_CURRENCY, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_Lobby_Theme_Subscribe, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_BOSS_DEPUTY_REQUEST, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_BOSS_CANCEL_DEPUTY, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_BOSS_TRANS_TABLE, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_DEPUTY_LOGIN, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_SET_CHIP, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_GET_CHIPS, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_MultiTable_Entry, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_LOBBY_INFO, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_CAN_ENTER_TABLE_STATUS, PacketMode.Receive);
            // encrypter.SetPrivateKeyPacketID(PacketID.S_LOGIN_OUT, PacketMode.Receive);
        }// else if(clientName==ClientName.GAME_CLIENT||clientName==ClientName.QUICK_GAME_CLIENT)
        // {
        //     ///  需要压缩数据的规则
        //     // encrypter.Ruler.SetNeedCompressPacket(PacketID.ENTER_TABLE, PacketMode.Send);
        //     // ///  需要解压缩数据的规则
        //     // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_ENTER_TABLE, PacketMode.Receive);
        //     // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_FAIL_GAME, PacketMode.Receive);
        //     // encrypter.Ruler.SetNeedDecompressPacket(PacketID.S_Game_Update_Table_Data, PacketMode.Receive);
        //     // ///  需要使用动态CDataKey的规则
        //     // encrypter.Ruler.SetNeedGenDynamicKey(PacketID.ENTER_TABLE, PacketMode.Send);
        //     // encrypter.Ruler.SetNeedGenDynamicKey(PacketID.S_ENTER_TABLE, PacketMode.Receive);
        //     // ////////////////////////////////////////////////////// BroadcastKey
        //     // // Client
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.PEEK_PROGRESS, PacketMode.Send);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.ACK, PacketMode.Send);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.N_ACK, PacketMode.Send);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.C_Heart, PacketMode.Send);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_Heart, PacketMode.Send);
        //     // // Server
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_TABLE_STATUS, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_REAL_TIME_BET_INFO, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_UPDATE_BET_INFO, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_DEAL_INFO, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_ERROR_MSG, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_TABLE_PAUSE, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_Game_Update_Table_Road, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.ACK, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.N_ACK, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.C_Heart, PacketMode.Receive);
        //     // encrypter.SetBroadcastKeyPacketID(PacketID.S_Heart, PacketMode.Receive);
        //     // ////////////////////////////////////////////////////// PrivateKey
        //     // // Client
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_SET_TABLE_SEAT, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_EXIT_TABLE, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_BET_INFO, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.CANCEL_BET, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_RESERVED_TABLE_OPERATION, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_ENTER_TABLE_OK, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_MULTI_TABLE_REQ, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_MULTI_TABLE_UNSUBSCRIBE, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_PEEK_OPEN_CARD, PacketMode.Send);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.C_Game_Update_Table_Data, PacketMode.Send);
        //     // // Server
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_TABLE_SEAT_UPDATE, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_SET_TABLE_SEAT, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_BET_INFO_AND_DEAL_INFO, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_EXIT_TABLE, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_BET_INFO, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_WIN_INFO, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_FAIL_GAME, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_PLAYER_IDLE_INFO, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_RESERVED_TABLE_OPERATION, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_GIVE_TIPS, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_CAN_ENTER_TABLE_STATUS, PacketMode.Receive);
        //     // encrypter.SetPrivateKeyPacketID(PacketID.S_Game_Update_Table_Data, PacketMode.Receive);
        // }
        encrypter.flush();
        return encrypter;
    }
    
    public static SetAgentKey(key:string,clientName:string):void
    {
        var encrypter:Encrypter = this.GetEncrypter(clientName);
        encrypter.AgentKey = key;
    }
    public static SetBroadcastKey(key:string,clientName:string):void
    {
        var encrypter:Encrypter = this.GetEncrypter(clientName);
        encrypter.BroadcastKey = key;
    }
    public static SetPrivateKey(key:string,clientName:string):void
    {
        var encrypter:Encrypter = this.GetEncrypter(clientName);
        encrypter.PrivateKey = key;
    }
}